using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragObj : MonoBehaviour
{
    Vector3 _pos;
    // Start is called before the first frame update
    void Start()
    {

    }
    public void SetPos(Vector3 pos)
    {
        StartCoroutine(StatrMove(pos));
    }
    IEnumerator StatrMove(Vector3 pos)
    {
        while (true)
        {
            if (Vector3.Distance(transform.position, pos) >= 0.1f)
            {
                transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * 5);
            }
            else
            {
                var dis = Vector3.Distance(DragGameMgr.Ins.Drag.transform.position, transform.position);
                Debug.Log(dis);

                if (dis <= 0.1f)
                {
                    DragGameMgr.Ins.dragNum += 50;
                }
                else if (dis <= 0.25f)
                {
                    DragGameMgr.Ins.dragNum += 25;
                }
                else if (dis <= 0.5f)
                {
                    DragGameMgr.Ins.dragNum += 2;
                }
                else
                {
                    GetComponent<Rigidbody>().useGravity = true;
                    Destroy(gameObject, 1f);
                }
                break;
            }
            yield return null;
        }
    }
}